package spring.cloud.simple.provider;

import java.util.Map;
import java.util.Random;

import org.springframework.stereotype.Component;

import spring.cloud.simple.interfaces.UserService;
import spring.cloud.simple.config.ZooKeeperConfig;

@Component
public class UserServiceProvider {
    public UserService.Client getBalanceUserService() {
        Map<String, UserService.Client> serviceMap = ZooKeeperConfig.serviceMap;
        for (Map.Entry<String, UserService.Client> entry : serviceMap.entrySet()) {
            System.out.println("Optional service: " + entry.getKey());
        }
        int rand = new Random().nextInt(serviceMap.size());
        String[] keys = serviceMap.keySet().toArray(new String[serviceMap.size()]);
        return serviceMap.get(keys[rand]);
    }
}
